package com.zbs.test.task;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import com.zbs.test.utils.RabbitMqUtil;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Task02 {

    final static String queueName = "ack_test";

    /**
     * 生产者
     * @param args
     * @throws IOException
     * @throws TimeoutException
     */
    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMqUtil.getChannel();
        /**
         * 1 队列名称
         * 2 队列是否持久化
         * 3 消息是否共享  开启共享后可以多个消费者使用
         * 4 消息是否自动删除
         */
        boolean durable = true;
        channel.queueDeclare(queueName,durable,false,false,null);

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String next = scanner.next();
            channel.basicPublish("",queueName, MessageProperties.PERSISTENT_TEXT_PLAIN,next.getBytes(StandardCharsets.UTF_8));
            System.out.println("发送消息完成："+next);
        }


    }
}
